<script>
export default {
    name: "orgnazition",
    data() {
        return {
            columns: [
                {
                    title: "演练任务名称",
                    key: "taskName",
                    sortable: true,
                },
                {
                    title: "组织结构名称",
                    key: "orgName",
                    sortable: true,
                    width: 130,
                },
                {
                    title: "开始时间",
                    key: "startTime",
                    sortable: true,
                    width: 110,
                },
                {
                    title: "结束时间",
                    key: "endTime",
                    sortable: true,
                    width: 110,
                },
                {
                    title: "任务状态",
                    slot: "taskStatus",
                    sortable: true,
                },
                {
                    title: "完成状态",
                    slot: "finishedStatus",
                    sortable: true,
                },
                {
                    title: "漏洞扫描个数",
                    key: "submitScanNum",
                    sortable: true,
                },
                {
                    title: "漏洞利用个数",
                    key: "submitExploitNum",
                    sortable: true,
                },
                {
                    title: "横向移动个数",
                    key: "submitMoveNum",
                    sortable: true,
                },
                {
                    title: "相关操作",
                    width: 180,
                    slot: "action"
                }
            ],
            taskData: [], //全部数据
            taskStatusStr: {
                1: "进行中",
                2: "已结束",
            },
            finishedStatusStr: {
                0: "未接受",
                1: "已接受未完成",
                2: "已完成",
                3: "拒绝接受",
            },
        };
    },
    methods: {
        handleAccept(id) {
            this.$api.post("tester/task/accept",{id: id}).then((res)=>{
                this.info(res.msg);
                this.renew();
            })
        },
        handleFinish(id) {
            this.$api.post("tester/task/finish",{id: id}).then((res)=>{
                this.info(res.msg);
                this.renew();
            })
        },
        handleRefuse(id) {
            console.log(id);
            this.$api.post("tester/task/refuse",{id: id}).then((res)=>{
                this.info(res.msg);
                this.renew();
            })
        },
        confirm(func) {
            this.$Modal.confirm({
                title: "确认框",
                onOk: func,
            });
        },
        confirm(func, msg) {
            this.$Modal.confirm({
                title: "确认框",
                content: msg,
                onOk: func,
            });
        },
        renew() {
            this.$api.get("tester/task/list").then((res) => {
                this.taskData = res.data.data;
                console.log(this.taskData);
            })
        },
        info(message) {
            this.$Notice.info({
                title: "提示",
                desc: message,
            });
        },
    },
    created() {
        this.renew();
    },
}
</script>
<template>
    <div class="main_container">
        <div class="table_container">
            <Table highlight-row border :columns="columns" :data="taskData" width="1115" height="520" row-key="id">
                <template #action="{ row }">
                    <div class="buttonGroup">
                        <Button type="info" @click="handleAccept(row.id)" v-show="row.finishedStatus == 0">接受</Button>
                        <Button type="success" @click="handleFinish(row.id)" v-show="row.finishedStatus == 1">完成</Button>
                        <Button type="error" @click="handleRefuse(row.id)" v-show="row.finishedStatus == 0">拒接</Button>
                    </div>
                </template>
                <template #taskStatus="{ row }">
                    {{ taskStatusStr[row.taskStatus] }}
                </template>
                <template #finishedStatus="{ row }">
                    {{ finishedStatusStr[row.finishedStatus] }}
                </template>
            </Table>
        </div>
    </div>
</template>
<style scoped>
.main_container {
    width: 90%;
    height: 90%;
    border-radius: 10px;
    padding: 10px;
    border: solid;
    margin: auto;
    margin-top: 20px;
}

.table_container {
    width: 100%;
    height: 90%;
    /* overflow: scroll; */
}

.add_btn {
    margin: 10px auto;
    margin-left: 80%;
    width: 160px;
}
.buttonGroup{
    display: flex;
    justify-content:space-around;
}
</style>